<div class="clearfix dialog_link_to">
  <div id="dialog_menu_left">
    <span id="your_page_radio" class="radio<%= ' selected_radio' if @page_area_selected %>">
      <input type="radio" name="link_to" value="your_page" id="link_to_your_page" <%= 'checked="true"'.html_safe if @page_area_selected %> />
      <label for="link_to_your_page" class="stripped"><%= t('.your_page.tab_name') %></label>
    </span>
    <span id="web_address_radio" class="radio<%= ' selected_radio' if @web_address_area_selected %>">
      <input type="radio" name="link_to" value="web_address" id="link_to_web_address" <%= 'checked="true"'.html_safe if @web_address_area_selected %> />
      <label for="link_to_web_address" class="stripped"><%= t('tab_name', :scope => 'refinery.admin.pages_dialogs.link_to.web_address') %></label>
    </span>

    <span id="email_address_radio" class="radio<%= ' selected_radio' if @email_address_area_selected %>">
      <input type="radio" name="link_to" value="email_address" id="link_to_email_address" <%= 'checked="true"'.html_safe if @email_address_area_selected %> />
      <label for="link_to_email_address" class="stripped"><%= t('tab_name', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %></label>
    </span>
    <% if ::Refinery::Plugins.registered.names.include?("refinery_files") and @resources.any? %>
      <span id="resource_file_radio" class="radio<%= ' selected_radio' if @resource_area_selected %>">
        <input type="radio" name="link_to" value="resource_file" id="link_to_resource_file" <%= 'checked="true"'.html_safe if @resource_area_selected %> />
        <label for="link_to_resource_file" class="stripped"><%= t('tab_name', :scope => 'refinery.admin.pages_dialogs.link_to.your_resource') %></label>
      </span>
    <% end %>
  </div>

  <div id="dialog_main">
    <div id="your_page_area" class="dialog_area" <%= ' class="linked"'.html_safe unless @page_area_selected %>>
      <input type="hidden" name="selected_image" id="selected_image" />
      <div id="your_page_content" class="clearfix">
        <div id="pages_list" class="pages_list">
          <ul class="link_list">
            <%= render :partial => 'page_link', :collection => @pages,
                       :locals => {
                         :child => 0,
                         :link_to_arguments => {}
                       } %>
          </ul>
          <%= will_paginate @pages, :id => 'pages_paginate' %>
        </div>
      </div>
    </div>
    <div id="web_address_area" <%= 'style="display: none"'.html_safe unless @web_address_area_selected %> class="dialog_area">
      <div id="web_address_content">
        <label for="web_address_text"><%= t('location', :scope => 'refinery.admin.pages_dialogs.link_to.web_address') %></label>
        <%= text_field :web_address, :text, :value => @web_address_text, :style => "width: 70%" %>
        <label><%= t('new_window', :scope => 'refinery.admin.pages_dialogs.link_to.web_address') %></label>
        <input type="checkbox" name="web_address_target_blank" id="web_address_target_blank" <%= 'checked="checked"'.html_safe if @web_address_target_blank %> />
        <label for="web_address_target_blank" class="stripped"><%= t('new_window_label', :scope => 'refinery.admin.pages_dialogs.link_to.web_address') %></label>
        <p>
          <strong><%= t('not_sure', :scope => 'refinery.admin.pages_dialogs.link_to.web_address') %></strong>
        </p>
        <ol>
          <li><%= t('step1', :scope => 'refinery.admin.pages_dialogs.link_to.web_address') %></li>
          <li><%= t('step2', :scope => 'refinery.admin.pages_dialogs.link_to.web_address') %></li>
        </ol>
      </div>
    </div>
    <div id="email_address_area" <%= 'style="display: none"'.html_safe unless @email_address_area_selected %> class="dialog_area">
      <div id="email_address_content">
        <div class="field">
          <label for="email_address_text"><%= t('tab_name', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %></label>
          <%= text_field :email_address, :text, :value => @email_address_text, :style => "width: 70%" %>
        </div>

        <div class="field">
          <label for="email_default_subject_text"><%= t('subject_line_optional', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %></label>
          <%= text_field :email_default_subject, :text, :value => @email_default_subject_text, :style => "width: 70%" %>
        </div>

        <div class="field">
          <label for="email_default_body_text"><%= t('body_optional', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %></label>
          <%= text_area :email_default_body, :text, :value => @email_default_body_text, :style => "width: 70%", :rows => '' %>
        </div>

        <p>
          <strong><%= t('not_sure', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %></strong>
        </p>
        <ol style='margin-top: 3px'>
          <li>
            <%= t('step1_html', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %>
          </li>
          <li>
            <%= t('step2_html', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %>
          </li>
          <li>
            <%= t('step3_html', :scope => 'refinery.admin.pages_dialogs.link_to.email_address') %>
          </li>
        </ol>
      </div>
    </div>
    <% if ::Refinery::Plugins.registered.names.include?("refinery_files") and @resources.any? %>
      <div id="resource_file_area"<%= ' style="display:none"'.html_safe unless @resource_area_selected %> class="dialog_area">
        <div id="resources_list" class="pages_list">
          <ul class="link_list">
            <% @resources.each do |resource| -%>
              <% resource_linked = (resource.url == params[:current_link]) unless params[:current_link].blank? %>
              <li<%= ' class="linked"'.html_safe if resource_linked %>>
                <%= link_to "#{resource.title}.#{resource.ext}", path_to_asset(resource.url),
                            :title => t('link_to_this_resource', :scope => 'refinery.admin.pages_dialogs.link_to.your_resource'),
                            :rel => resource.title,
                            :class => "page_link #{resource.ext}" %>
              </li>
            <% end %>
          </ul>
          <%= will_paginate @resources,
                           :param_name => :resource_page,
                           :params => {:paginating => "resource_file"},
                           :id => 'resouces_paginate' %>
        </div>
      </div>
    <% end %>
  </div>
  <%= render '/refinery/admin/form_actions', :f => nil,
             :cancel_url => '',
             :submit_button_text => t('.insert'),
             :hide_cancel => false,
             :cancel_title => nil,
             :hide_delete => true %>
</div>

<% content_for :javascripts do %>
  <script>
    $(document).ready(function(){
      link_dialog.init();

      $('.link_list a').click(function(e){
        e.preventDefault();
      });
    });
  </script>
<% end %>
